package com.lhys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lhys.mapper.AssetProviderMapper;
import com.lhys.pojo.AssetProvider;
import com.lhys.service.AssetProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 资产_供应商表 服务实现类
 * </p>
 *
 * @author 小七
 * @since 2021-05-06
 */
@Service
public class AssetProviderServiceImpl implements AssetProviderService {
    @Autowired
    private AssetProviderMapper assetProviderMapper;

    @Override
    @Transactional
    public Boolean saveAssetProvider(AssetProvider assetProvider) {
        try {
            if (assetProvider.getId() == null) {
                assetProvider.setCreateTime(new Date());
                return assetProviderMapper.addAssetProvider(assetProvider) > 0;
            }
            return assetProviderMapper.updateAssetProvider(assetProvider) > 0;
        } catch (Exception e) {
            System.out.println("重复添加");
            return null;
        }
    }

    @Override
    @Transactional
    public Boolean delAssetProviderById(Integer id) {
        return assetProviderMapper.delAssetProvider(id) > 0;
    }

    @Override
    public AssetProvider getAssetProviderById(Integer id) {
        return assetProviderMapper.getAssetProviderById(id);
    }

    @Override
    public PageInfo<AssetProvider> getAssetProviderList(AssetProvider assetProvider, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<AssetProvider> list = assetProviderMapper.getAssetProviderByStatusAndProviderTypeIdAndTitleList(assetProvider);
        PageInfo<AssetProvider> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
